//
//  LandPageViewController.m
//  豆瓣终极版
//
//  Created by dllo on 15/12/19.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "LandPageViewController.h"
#import "LandView.h"
#import "RegisterViewController.h"
@interface LandPageViewController ()<LandViewDelegate>


@end

@implementation LandPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"用户登陆";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(returnBtn:)];
    
    LandView *landview = [[LandView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:landview];
    landview.landDelegate = self;
    
}

- (void)passByValueToLandPageVCUserName:(NSString *)name key:(NSString *)key{
    
    if ([name isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"userName"]] && [key isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"key"]]) {
        // 先从NSUserDefaults里去如果用户名和密码存在就模态回去
        [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"state"];
        [self dismissViewControllerAnimated:YES completion:^{
            
            
        }];
    } else if ([name isEqualToString:@""]){
        // 添加提示框
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名不能为空" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alertC animated:YES completion:^{
            
            
        }];

        UIAlertAction *confirmAlert = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alertC addAction:confirmAlert];
    } else if ([key isEqualToString:@""]){
        // 添加提示框
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"密码不能为空" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alertC animated:YES completion:^{
            
            
        }];

        UIAlertAction *confirmAlert = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alertC addAction:confirmAlert];
    } else if ([name isEqualToString:@""] && [key isEqualToString:@""]){
    
        // 添加提示框
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码不能为空" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alertC animated:YES completion:^{
            
            
        }];

        UIAlertAction *confirmAlert = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alertC addAction:confirmAlert];
        
        
    }else {
        // 添加提示框
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户不存在" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alertC animated:YES completion:^{
            
            
        }];

        UIAlertAction *confirmAlert = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alertC addAction:confirmAlert];
    }
}

- (void)returnBtn:(UIBarButtonItem *)btn{
    // dis回用户页面
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}
// 成为LandView的代理人
- (void)letLandPageViewPushToRegisterView{
    // push到注册页面
    RegisterViewController *registerVC = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:registerVC animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
